package com.dianrui.qiyouriding.baidumap;

import android.content.Context;

import com.baidu.location.BDAbstractLocationListener;
import com.baidu.location.LocationClient;
import com.baidu.location.LocationClientOption;

/**
 * 百度定位
 * Created by leilei on 2018/3/24.
 */

@SuppressWarnings("ALL")
public class LocationBaiduClient {
    public LocationClient mLocationClient = null;

    /**
     * @param context
     * @param scanSpan                   定位频率
     * @param isKillProcess              是否在stop的时候杀死这个进程
     * @param bdAbstractLocationListener
     */

    /*
          <service
            android:name="com.baidu.location.f"
            android:enabled="true"
            android:process=":remote" >
        </service>
    *
    * */
    public LocationBaiduClient(Context context, int scanSpan, boolean isKillProcess, BDAbstractLocationListener bdAbstractLocationListener) {
        mLocationClient = new LocationClient(context);
        mLocationClient.registerLocationListener(bdAbstractLocationListener);
        LocationClientOption option = new LocationClientOption();
        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
        option.setPriority(LocationClientOption.GpsFirst);
        option.setCoorType("bd09ll");
        option.setOpenGps(true);
        option.setLocationNotify(true);
        option.setIgnoreKillProcess(isKillProcess);
        option.SetIgnoreCacheException(false);
        option.setWifiCacheTimeOut(5*60 * 1000);
        option.setIsNeedAltitude(false);//设置定位时是否需要海拔信息， 默认不需要
        option.setIsNeedAddress(true);
        option.setIsNeedLocationDescribe(true);
        option.setIsNeedLocationPoiList(true);
        mLocationClient.setLocOption(option);
    }

    /**
     * 开始定位
     */
    public void start() {
        if (mLocationClient != null) {
            if (mLocationClient.isStarted()) {
                mLocationClient.restart();
            } else {
                mLocationClient.start();

            }

        }
    }


    public void requestLocation(){
        if (mLocationClient != null) {
            mLocationClient.requestLocation();

        }
    }


    /**
     * 停止定位
     */
    public void stop() {
        if (mLocationClient != null) {
            mLocationClient.stop();
        }
    }
}
